Product Code Database
Example Keywords: grand theft -trousers $36-128
barcode-scavenger
   » » Wiki: Even–odd Rule
Tag Wiki 'Even–odd Rule'.
Tag

Even–odd rule
 (

Rank: 100%
Bluestar Bluestar Bluestar Bluestar Blackstar

The even–odd rule is an implemented in vector-based graphic software,J. D. Foley, A. van Dam, S. K. Feiner, and J. F. Hughes. Computer Graphics: Principles and Practice. The Systems Programming Series. Addison-Wesley, Reading, 2nd edition, 1990. like the language and Scalable Vector Graphics (SVG), which determines how a graphical shape with more than one closed outline will be filled. Unlike the algorithm, this algorithm will alternatively color and leave uncolored shapes defined by nested closed paths irrespective of their winding.

The SVG defines the even–odd rule by saying:

The rule can be seen in effect in many vector graphic programs (such as Freehand or Illustrator), where a crossing of an outline with itself causes shapes to fill in strange ways.

On a simple curve, the even–odd rule reduces to a decision algorithm for the point in polygon problem.

The SVG computer vector graphics standard may be configured to use the even–odd rule when drawing polygons, though it uses the by default.[1], w3c.org, retrieved 2019-03-28


Implementation
Below is a partial example implementation in Python, by using a ray to the right of the point being checked: def is_point_in_path(x: int, y: int, poly: listtuple[int,]) -> bool:
   """Determine if the point is on the path, corner, or boundary of the polygon
     

   Args:
     x -- The x coordinates of point.
     y -- The y coordinates of point.
     poly -- a list of tuples [(x, y), (x, y), ...]
     

   Returns:
     True if the point is in the path or is a corner or on the boundary"""
   c = False
   for i in range(len(poly)):
       ax, ay = poly[i]
       bx, by = poly[i - 1]
       if (x == ax) and (y == ay):
           # point is a corner
           return True
       if (ay > y) != (by > y):
           slope = (x - ax) * (by - ay) - (bx - ax) * (y - ay)
           if slope == 0:
               # point is on boundary
               return True
           if (slope < 0) != (by < ay):
               c = not c
   return c
     


See also


External links

Page 1 of 1
1
Page 1 of 1
1

Account

Social:
Pages:  ..   .. 
Items:  .. 

Navigation

General: Atom Feed Atom Feed  .. 
Help:  ..   .. 
Category:  ..   .. 
Media:  ..   .. 
Posts:  ..   ..   .. 

Statistics

Page:  .. 
Summary:  .. 
1 Tags
10/10 Page Rank
5 Page Refs